package cn.lkx.serviceoss.controller;

import cn.lkx.commonutils.R;
import cn.lkx.serviceoss.service.OssService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(description = "OSS文件上传")
@RestController
@RequestMapping("/eduoss/ossfile")
@CrossOrigin //跨域
public class OssController {
    @Autowired
    OssService ossService;

    //上传头像方法
    @PostMapping("upload")
    public R uploadOssFile(MultipartFile file){
        //获取上传文件 MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadAvatar(file);
        System.err.println(url);
        return R.ok().data("url",url).message("上传成功");
    }
}
